class RequestEventEmitter {
  event: any
  constructor() {
    this.event = {}
  }
  on(type: any, cbRes: any, cbRej: any) {
    if (!this.event[type]) {
      this.event[type] = [[cbRes, cbRej]]
    } else {
      this.event[type].push([cbRes, cbRej])
    }
  }

  emit(type: any, res: any, ansType: any) {
    if (!this.event[type]) return
    this.event[type].forEach((cbArr: any) => {
      const index = ansType === 'resolve' ? 0 : 1
      cbArr[index](res?.data)
    })
  }
}

export const requestBus = new RequestEventEmitter()
